﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Rendering.GlobalKeyword
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System.Runtime.CompilerServices;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Rendering
{
  /// <summary>
  ///   <para>Represents a global shader keyword.</para>
  /// </summary>
  [NativeHeader("Runtime/Shaders/Keywords/KeywordSpaceScriptBindings.h")]
  [NativeHeader("Runtime/Graphics/ShaderScriptBindings.h")]
  [UsedByNativeCode]
  public readonly struct GlobalKeyword
  {
    internal readonly string m_Name;
    internal readonly uint m_Index;

    [FreeFunction("ShaderScripting::GetGlobalKeywordCount")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern uint GetGlobalKeywordCount();

    [FreeFunction("ShaderScripting::GetGlobalKeywordIndex")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern uint GetGlobalKeywordIndex(string keyword);

    [FreeFunction("ShaderScripting::CreateGlobalKeyword")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void CreateGlobalKeyword(string keyword);

    /// <summary>
    ///   <para>The name of the shader keyword. (Read Only)</para>
    /// </summary>
    public string name => this.m_Name;

    /// <summary>
    ///   <para>Creates and returns a Rendering.GlobalKeyword that represents a new or existing global shader keyword.</para>
    /// </summary>
    /// <param name="name">The name of the global shader keyword.</param>
    /// <returns>
    ///   <para>Returns a new instance of the GlobalKeyword class.</para>
    /// </returns>
    public static GlobalKeyword Create(string name)
    {
      GlobalKeyword.CreateGlobalKeyword(name);
      return new GlobalKeyword(name);
    }

    /// <summary>
    ///   <para>Creates and returns a GlobalKeyword struct that represents an existing global shader keyword.</para>
    /// </summary>
    /// <param name="name">The name of the global shader keyword.</param>
    public GlobalKeyword(string name)
    {
      this.m_Name = name;
      this.m_Index = GlobalKeyword.GetGlobalKeywordIndex(name);
      if (this.m_Index < GlobalKeyword.GetGlobalKeywordCount())
        return;
      Debug.LogErrorFormat("Global keyword {0} doesn't exist.", (object) name);
    }

    public override string ToString() => this.m_Name;
  }
}
